<?php

	/**
	 * @see Bike_Js_Ext_ComponentLoader
	 */
	require_once 'Bike/Js/Ext/ComponentLoader.php';
	
	
	class Bike_Js_Ext_ComponentLoader_Custom extends Bike_Js_Ext_ComponentLoader
	{
		protected function initDefaultSettings()
		{
			parent::initDefaultSettings();
		
			$this->setSettings(array(
				'renderer' => $this->getJsRenderer(),				
			));
		}
		
		/**
		 * Get JS renderer
		 *
		 * @return Bike_Js_Interface_Js object
		 */
		protected function getJsRenderer()
		{
			if(!$this->getParamCache(__METHOD__))
			{
				$js = $this->js();
				$this->setParamCache(__METHOD__,
					$js->function($js->loader, $js->response, $js->options)->_body(array(
						$js->TryCatch
							->_tryBody(array(
								$js->_var($js->Response)->_val($js->Ext->JSON->decode($js->response->responseText)),
								$js->if($js->typeof($js->Response->handler)->_eq('function'))->_body(array(
									$js->Response->handler->call($js->loader->getTarget(), $js->loader, $js->response, $js->options),
								)),
								$js->loader->getTarget()->doLayout(),
							))
							->_catchBody(array(
							    $js->Ext->Msg->Error($js->e),
								$js->TryCatch->_tryBody(array(
									$js->loader->getTarget()->close(),
								)),								
							)),
					))
				);
			}
			return $this->getParamCache(__METHOD__);
		}
	}
